/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.gui.client;

import com.google.gwt.user.client.ui.FlexTable;
/*import com.google.gwt.user.client.ui.PopupListener;
import com.google.gwt.user.client.ui.PopupPanel;
import com.gwtext.client.core.Position;
import nfse.gui.query.QuerySummary;
import nfse.gui.query.QueryOptions;
import nfse.gui.query.*;

import com.gwtext.client.data.*;
import com.gwtext.client.widgets.*;
import com.gwtext.client.widgets.event.*;
import com.gwtext.client.widgets.tree.*;
import com.gwtext.client.widgets.tree.event.*;
import com.gwtext.client.widgets.form.*;
import com.gwtext.client.widgets.layout.*;
import com.gwtext.client.widgets.menu.BaseItem;  
import com.gwtext.client.widgets.menu.Item;  
import com.gwtext.client.widgets.menu.Menu;  
import com.gwtext.client.widgets.menu.event.BaseItemListenerAdapter;  
import com.gwtext.client.widgets.event.TabPanelListenerAdapter;  

import java.util.*;*/

//public class SearchAnalysisTab extends FlexTable implements PopupListener
public class SearchAnalysisTab extends FlexTable

{


//	private Panel rootPanel = new Panel();
//	private Panel mainPanel = new Panel();
//	private Panel leftPanel = new Panel();
//	private TreePanel treePanel = new TreePanel();
//	private Panel accordionPanel = new Panel();
//	
//	private SearchPanel searchPanel;
//	private SearchResultsPanel searchResultsPanel; 
//	public AnalysisPanelGroup analysisPanelGroup;
//	private SearchHistoryPanel searchHistoryPanel;
//	private BaseGridPanel testGridPanel;
//	private int numberOfPanels = 4; 
//	
//	private Panel resultDetail = new Panel();
//	HashMap resultMap = new HashMap();
//	private ArrayList resultList = new ArrayList();
//
//	private Panel historyDetail = new Panel();
//	HashMap historyMap = new HashMap();
//	private ArrayList historyList = new ArrayList();
//	
//	private NetFSEClient client;
//	HashMap analysisTabMap = new HashMap();
//	boolean placeHolderVisible = true;
//	boolean deleteSelectedTab = false;
//	public TreeNode resultRoot = new TreeNode("Results");
//	public TreeNode historyRoot = new TreeNode("History");
//	public TreeNode root = new TreeNode("Functional Areas");
//    private ArrayList panelsCompleteList = new ArrayList();
//	
//	TabPanel analysisTabPanel = new TabPanel();
//	
//	//private boolean readyForToBuildTab = false;
	
	public SearchAnalysisTab(NetFSEClient client)
	{
//		this.client = client;
	}
	
//	/**
//	 * All the panels are dependent on the retrieval of the types. So don't start creating the panels until the types are retrieved
//	 */
//	public void typesHaveBeenRetrieved()
//	{
//		//Build the panels for each section of SearchAnalysisTab
//		//The sections are: Results Tree, Search Panel, Result Panel, Analysis Panel, History Panel
//
//		searchPanel = new SearchPanel(client,this);
//		searchResultsPanel = new SearchResultsPanel(client,this);
//		analysisPanelGroup = new AnalysisPanelGroup(client,this);
//		searchHistoryPanel = new SearchHistoryPanel(client,this);	
//		//testGridPanel = new BaseGridPanel(client,null);		
//		//buildAnalysisTab();
//	}
//	
//	public void checkIfReadyToBuild(Panel corePanel)
//	{
//	    if (!panelsCompleteList.contains(corePanel))
//		{
//			panelsCompleteList.add(corePanel);
//		}
//		//Check to see if all the panel rpc calls have returned
//		if (panelsCompleteList.size() == numberOfPanels)
//		{			
//			searchPanel.buildPanel();
//			searchResultsPanel.buildPanel();
//			analysisPanelGroup.buildPanel();
//			searchHistoryPanel.buildPanel();
//			buildAnalysisTab();
//			//Reset list for next time that the page is built
//			panelsCompleteList.clear();		
//		}
//	}
//	
//	
//	public void buildResultsTree()
//	{
//		QuerySummary[] qs = client.searchResultsTab.getQuerySummary();
//		for (int i = 0; i < qs.length; i++)
//		{
//			if (!resultList.contains(qs[i].queryID))
//			{
//				TreeNode queryIdNode = new TreeNode(qs[i].queryID);
//				//qs[i].note = "The query id is "+ qs[i].queryID + " \nwhatever else you want to say \n now that it can be said. What do you think";
//				
//				queryIdNode.setTooltip(qs[i].ts + "<br>" + qs[i].note);
//				
//				queryIdNode.addListener(new TreeNodeListenerAdapter() 
//			     {
//			    	 public void onClick(Node node, com.gwtext.client.core.EventObject e)
//			    	 {			    		 
//			    		  String nodeId = ((TreeNode)node).getText();
//			    		  System.out.println("Clicked on node " + nodeId + " Displaying Result Detail");
//			    		  if (resultMap.get(nodeId) != null)
//			    		  {
//			    			  QuerySummary localQS = (QuerySummary)resultMap.get(nodeId); 
//			    			  resultDetail.setHtml(formatResultDetail(localQS));
//			    		  }
//			    	 }
//			    	 
//			    	 public void onDblClick(Node node, com.gwtext.client.core.EventObject e)
//			    	 {
//			    		  String nodeId = ((TreeNode)node).getText();
//			    		  System.out.println("Double Clicked on node " + nodeId);
//			    		  if (analysisTabMap.get(nodeId) == null)
//			    			  client.openQuery(nodeId);
//
//			    	 }
//
//			     });
//				resultList.add(qs[i].queryID);
//				resultMap.put(qs[i].queryID, qs[i]);
//				resultRoot.appendChild(queryIdNode);
//			}
//		}
//		resultRoot.expand();
//		
//	}
//	
//	private String formatResultDetail(QuerySummary qs)
//	{
//		  StringBuffer sb = new StringBuffer();
//		  sb.append("<table class='result-detail'>");
//		  sb.append("<tr>");
//		  sb.append("<td class='result-detail-tdleft'>");
//		  sb.append("Query Id");		  
//		  sb.append("</td>");
//		  sb.append("<td class='result-detail-tdright'>");
//		  if (qs == null)
//			  sb.append("-");
//		  else
//			  sb.append(qs.queryID);		  
//		  sb.append("</td>");		  
//		  sb.append("</tr>");
//
//		  sb.append("<tr>");
//		  sb.append("<td class='result-detail-tdleft'>");
//		  sb.append("Status");		  
//		  sb.append("</td>");
//		  sb.append("<td class='result-detail-tdleft'>");
//		  if (qs == null)
//			  sb.append("-");
//		  else		 
//			  sb.append(getSearchResultStatusName(qs.status));		  
//		  sb.append("</td>");		  
//		  sb.append("</tr>");
//		  
//		  sb.append("<tr >");
//		  sb.append("<td class='result-detail-spacer'  colspan='2'>");
//		  sb.append("***************************");
//		  sb.append("</td>");
//		  sb.append("</tr>");
//		  
//		  sb.append("<tr>");
//		  sb.append("<td class='result-detail-tdleft'  colspan='2'>");
//		  sb.append("Counts");		  
//		  sb.append("</td>");
//		  sb.append("</tr>");
//
//			for (int i = 0; i < client.getAllTypes().length; i++)
//			{
//				  sb.append("<tr>");
//				  sb.append("<td class='result-detail-tdleft'>");
//				  sb.append(client.getTypeName(client.getAllTypes()[i]));		  
//				  sb.append("</td>");
//				  sb.append("<td class='result-detail-tdright'>");
//				  if (qs == null)
//					  sb.append("-");
//				  else				 
//					  sb.append(qs.getTypeCount(client.getAllTypes()[i]));		  
//				  sb.append("</td>");		  
//				  sb.append("</tr>");
//			}
//			sb.append("</table>");
//		    return sb.toString();
//	}
//	
//	private String getSearchResultStatusName(int statusId)
//	{
//        String status = "In progress";
//        if (statusId == 1)
//            status = "Complete";
//        else if (statusId == 2)
//            status = "Merging";
//        
//        return status;
//	}
//	
//	
//	public void buildHistoryTree()
//	{
//		QueryOptions[] qo = client.searchHistoryTab.getHistoryData();
//		
//		for (int i = 0; i < qo.length; i++)
//		{
//			if (!historyList.contains(qo[i].queryID))
//			{
//				TreeNode queryIdNode = new TreeNode(qo[i].queryID);
//				
//				queryIdNode.addListener(new TreeNodeListenerAdapter() 
//			     {
//			    	 public void onClick(Node node, com.gwtext.client.core.EventObject e)
//			    	 {			    		 
//			    		  String nodeId = ((TreeNode)node).getText();
//			    		  System.out.println("Clicked on node " + nodeId + " Displaying History Detail");
//			    		  if (historyMap.get(nodeId) != null)
//			    		  {
//			    			  QuerySummary localQS = (QuerySummary)historyMap.get(nodeId); 
//			    			  StringBuffer sb = new StringBuffer();
//			    			  sb.append("Query Id: " + localQS.queryID + "<br>");
//			    			  sb.append("Count:" +  localQS.count + "<br>");
//			    			  sb.append("Status: " + localQS.status + "<br>");
//			    			  historyDetail.setHtml(sb.toString());
//			    		  }
//			    	 }
//			    	 
//			    	 public void onDblClick(Node node, com.gwtext.client.core.EventObject e)
//			    	 {
//			    		  String nodeId = ((TreeNode)node).getText();
//			    		  System.out.println("Double Clicked on node " + nodeId);
//			    		  if (analysisTabMap.get(nodeId) == null)
//			    			  client.openQuery(nodeId);
//
//			    	 }
//
//			     });
//				historyList.add(qo[i].queryID);
//				historyMap.put(qo[i].queryID, qo[i]);
//				historyRoot.appendChild(queryIdNode);
//			}
//		}
//		
//		
//	}
//	
//	public void buildAnalysisTab()
//	{
//		
//		com.gwtext.client.widgets.layout.VerticalLayout rootVLayout = new com.gwtext.client.widgets.layout.VerticalLayout();
//		
//		rootPanel.setWidth(1072);
//		rootPanel.setLayout(rootVLayout);
//		//rootPanel.setAutoWidth(true);
//		com.gwtext.client.widgets.layout.HorizontalLayout hLayout = new com.gwtext.client.widgets.layout.HorizontalLayout(0);
//		hLayout.setColumns(2);
//		mainPanel.setLayout(hLayout);
//		mainPanel.setWidth(1071);
//		//mainPanel.setAutoWidth(true);
//		//mainPanel.setFrame(true);  Use for rounded corners
//		treePanel.setTitle("Result Master");
//		treePanel.setSelectionModel(new DefaultSelectionModel());
//				    	     	     
//	     treePanel.setRootNode(root);
//	     treePanel.setRootVisible(false);
//	     treePanel.setHeight(248);
//	     treePanel.setWidth(120);
//	     treePanel.setAutoScroll(true);
//	     	     	     
//	     resultRoot.addListener(new TreeNodeListenerAdapter() 
//	     {
//	    	 public void onClick(Node node, com.gwtext.client.core.EventObject e)
//	    	 {
//	    		  System.out.println("Clicked on Result Node");
//	    	 }
//	    	 
//	    	 public void onDblClick(Node node, com.gwtext.client.core.EventObject e)
//	    	 {
//	    		 System.out.println("Double Clicked the node");
//	    	 }
//	     });
//	     
//	    root.appendChild(resultRoot);
//	    resultRoot.expand();
//	     
//        //root.appendChild(historyRoot);
//		//treePanel.setFrame(true);
//		
//		com.gwtext.client.widgets.layout.VerticalLayout vLayout = new com.gwtext.client.widgets.layout.VerticalLayout();
//		leftPanel.setLayout(vLayout);
//		
//		leftPanel.add(treePanel);
//		leftPanel.setWidth(122);
//		leftPanel.setBorder(true);
//		resultDetail.setTitle("Result Detail");
//		resultDetail.setBorder(true);
//		resultDetail.setHeight(350);
//		resultDetail.setWidth(120);
//    	
//	    
//	    resultDetail.setHtml(formatResultDetail(null));
//		leftPanel.add(resultDetail);
//		
//				
//		mainPanel.add(leftPanel);
//
//		
//		
//		//analysisTabPanel.setTitle("Analysis");
////		analysisTabPanel.setWidth(500);
//		analysisTabPanel.setHeight(473);
//		//analysisTabPanel.setBorder(true);
//		analysisTabPanel.setAutoScroll(true);
//		analysisTabPanel.setTabPosition(Position.TOP);
//		
//		
//		analysisTabPanel.addListener(new TabPanelListenerAdapter() {
//			
//				public void onTabChange(TabPanel source, Panel tab)
//				{
//		    		  if (resultMap.get(tab.getTitle()) != null)
//		    		  {
//		    			  QuerySummary localQS = (QuerySummary)resultMap.get(tab.getTitle()); 
//		    			  resultDetail.setHtml(formatResultDetail(localQS));
//		    		  }
//
//				}
//			
//		}
//		);
//		
//	    analysisTabPanel.addListener(new ContainerListenerAdapter() {
//	
//	    		boolean remove = false;
//	    		
//			             public boolean doBeforeRemove(Container self, Component component) {
//			            	 
//				               Component[] items = analysisTabPanel.getItems(); 
//				               
//				               if (placeHolderVisible && (items.length == 2)) 
//				               {
//				            	   System.out.println("Placeholder and length 2");
//				            	   placeHolderVisible = false;
//				            	   return true;
//				               }
//				               else if (!placeHolderVisible && (items.length > 0))
//				               {
//				            	   System.out.println("! Placeholder and length > 0");
//				            	   
////									            	   MessageBox.confirm("Confirm", "Are you sure you want to delete this?",  
////						     			                          new MessageBox.ConfirmCallback() {  
////						     			                              public void execute(String btnID) {
////						     			                            	  if (btnID.equals("yes"))
////						     			                            		  deleteTab(true);
////						     			                            	  else
////						     			                            		  deleteTab(false);
////						     			                              }  
////						     			                          }); 
//									  System.out.println("the tab delete is " + deleteSelectedTab);
//
//					            	   System.out.println("The tab was removed");
//					                   Component[] localItems = analysisTabPanel.getItems(); 
//					                   if (localItems.length == 1)
//					                	   addPlaceHolderTab();		
//					                   deleteTab(false);
//					                   return true;			            		  									            	   									            	   									            	  				            	   
//									  
//									  
//				               }
//				               else
//				               {
//				            	   System.out.println("All others");
//				               }
//
////				               if (deleteSelectedTab)
////				               {
////				            	   System.out.println("The tab was removed");
////				                   Component[] localItems = analysisTabPanel.getItems(); 
////				                   if (localItems.length == 1)
////				                	   addPlaceHolderTab();		
////				                   deleteTab(false);
////				                   return true;			            		  									            	   									            	   									            	  				            	   
////				               }
//				            deleteTab(false);   
//			            	return false;
//			             }  
//        }); 
//
//		accordionPanel.setLayout(new AccordionLayout(true));
//		accordionPanel.setHeight(600);
//		accordionPanel.setWidth(950);
//		//accordionPanel.setAutoWidth(true);
//		accordionPanel.setBorder(true);
//		
//		accordionPanel.add(searchPanel);
//		searchPanel.collapse();
//
//		accordionPanel.add(searchResultsPanel);
//		searchResultsPanel.collapse();
//
//		//accordionPanel.add(testGridPanel);
//		
//		accordionPanel.add(analysisPanelGroup);
//		analysisPanelGroup.collapse();
//		
//		accordionPanel.add(searchHistoryPanel);
//		searchHistoryPanel.collapse();
//		
//		mainPanel.add(accordionPanel);
//		rootPanel.add(mainPanel);
//		this.setWidget(0, 0, rootPanel);
//		
////		searchPanel.expand();
//		searchResultsPanel.expand();
////		analysisPanelGroup.expand();
////		searchHistoryPanel.expand();
//	}
//	
//	public void buildAnalysisPanel(String[] queryIds)
//	{
//		analysisPanelGroup.addQueryTabPanels(queryIds);
//		searchResultsPanel.collapse();
//		analysisPanelGroup.expand();
//	}
//	
//	
//	private boolean isRPCComplete(Panel targetPanel)
//	{
//		return false;
//	}
//	
//	
//	public void deleteTab(boolean deleteIt)
//	{
//		deleteSelectedTab = deleteIt;
//	}
//	
//	
//	public boolean getDeleteTab()
//	{
//		return deleteSelectedTab;
//	}
//	
//	
//	public void addAnalysisTab(String queryId)
//	{
//		AnalysisTab aTab = new AnalysisTab(client,queryId);
//		aTab.openQuery(queryId);
//		Panel tab = new Panel();
//		tab.add(aTab);
//		tab.setTitle(queryId);
//		tab.setClosable(true);
//		analysisTabPanel.add(tab);
//		
//		analysisTabPanel.setActiveTab(tab.getId());
//		hidePlaceHolderTab();
//	    analysisTabMap.put(queryId, analysisTabPanel);
//	}
//	
//	
//	public void deleteAnalysisTab(String queryId)
//	{
//		analysisTabMap.remove(queryId);
//	}
//
//	
//	private void hidePlaceHolderTab()
//	{
//        Component[] items = analysisTabPanel.getItems();  
//        for (int i = 0; i < items.length; i++) {  
//            Component component = items[i];  
//            if (component.getTitle().equals("Analysis")) 
//            {
//            	if (items.length == 1)
//            		addPlaceHolderTab();
//            	analysisTabPanel.remove(component);
//            }  
//        }
//        placeHolderVisible = false;
//	}
//	
//
//	private void addPlaceHolderTab()
//	{
//		Panel placeHolder = new Panel();
//		placeHolder.setHtml("Analysis View");
//		placeHolder.setTitle("Analysis");
//		analysisTabPanel.add(placeHolder);
//		
//		analysisTabPanel.hideTabStripItem(placeHolder.getId());
//		
//		placeHolderVisible = true;
//	}
//	
//
//	
//	public void onPopupClosed(PopupPanel sender, boolean autoClosed)
//	{
//		// TODO Auto-generated method stub
//
//	}
//
}
